package cn.iocoder.yudao.module.reading.controller.app.category;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.reading.controller.app.category.vo.CategoryRespVO;
import cn.iocoder.yudao.module.reading.convert.category.CategoryConvert;
import cn.iocoder.yudao.module.reading.dal.dataobject.category.CategoryDO;
import cn.iocoder.yudao.module.reading.service.category.CategoryService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import jakarta.annotation.Resource;
import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

/**
 * 用户 APP - 绘本分类
 *
 * @author 芋道源码
 */
@Tag(name = "用户 APP - 绘本分类")
@RestController
@RequestMapping("/reading/categories")
@Validated
@Slf4j
public class CategoryController {

    @Resource
    private CategoryService categoryService;

    @GetMapping("/list")
    @Operation(summary = "获得绘本分类列表")
    public CommonResult<List<CategoryRespVO>> getCategoryList(
            @Parameter(description = "语言类型", example = "en") @RequestParam(value = "lang", required = false) String lang) {
        List<CategoryDO> list;
        if (lang != null && !lang.isEmpty()) {
            list = categoryService.getActiveCategoriesByLanguage(lang);
        } else {
            list = categoryService.getActiveCategories();
        }
        return success(CategoryConvert.INSTANCE.convertList(list));
    }

}
